/*
 * Copyright (C) 拾光分享网 
 * All rights reserved, Designed By www.hiai.top.
 * Email：goodsking@163.com.
 */
package top.hiai.common.account;

import com.jfinal.plugin.activerecord.Db;

import top.hiai.common.model.User;

/**
* @Author www.hiai.top
* @Email  goodsking@163.com
* @Message 更多资源尽在www.hiai.top
* @Introduction 类的介绍:用户发帖规则
*/

public class UserRoleService {
	
	public static final UserRoleService me = new UserRoleService();
	
	public static final int ADD_ARTICLE = 5;		// 发表一个文章获取的积分
	public static final int ADD_REPLY = 1;			// 发表一个评论获取的积分
	public static final int WEI_GUI = 10;			// 违规将扣除的积分
	
	/**
	 * 给用户添加积分
	 * @param uid
	 * @return
	 */
	public int setAddUserPoints(int points,int uid){
		return Db.update(" update bbs_user set points=points+? where uid=? ", points,uid);
	}
	
	/**
	 * 减少用户的积分
	 * 先判断用户的积分是否够用户
	 * @param uid
	 * @return
	 */
	public boolean setCutUserPoints(int points,int uid){
		User user = UserService.me.getById(uid);
		int temp = user.getPoints();
		if(temp < points ){
			return false;
		}else{
			Db.update(" update bbs_user set points=points-? where uid=? ", points,uid);
			return true;
		}		
	}	
}